home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 6 / 006.d81 / pps #13 < prev    next >
Text File  |  2022-08-26  |  2KB  |  148 lines

  1.  PEEKs, POKEs, and SYSes -- Part 13
  2.  
  3.          by Jimmy Weiler
  4.  
  5. ======================================
  6. Location:65520      Hexadecimal: $FFF0
  7. Official Label: PLOT         Type: ROM
  8. Useful BASIC commands: SYS
  9. ======================================
  10.  
  11.  
  12.  
  13.   PLOT has two functions.  It can tell
  14.  
  15. you where the cursor is on the screen
  16.  
  17. and it can place the cursor anywhere
  18.  
  19. on the screen.
  20.  
  21.  
  22. It is relatively simple to use:
  23.  
  24.  
  25.  
  26. To place the cursor 9 across and 12
  27. down:
  28.  
  29. 10POKE782,9:POKE781,12:POKE783,0:SYS
  30.   65520
  31.  
  32.  
  33.  
  34. To read the current cursor position:
  35.  
  36. 10POKE783,1:SYS65520:HRIZ=PEEK(782):
  37.   VERT=PEEK(781)
  38.  
  39.  
  40.  
  41. * Warning!! NEVER plot a position that
  42. * is not on the screen.  Results are
  43. * unpredictable and often fatal to
  44. * everything in memory.
  45.  
  46.  
  47.  
  48.   You can achieve an effect similar to
  49.  
  50. PLOT by using the cursor direction
  51.  
  52. keys.  This is most easily illustrated
  53.  
  54. with a short program.
  55.  
  56.  
  57.  
  58. 10 GOSUB 100
  59. 20 INPUT "HORIZ & VERT POSITIONS";H,V
  60. 25 PRINT "<clr>"
  61. 30 PRINT LEFT$ (ACROSS$,H+1);
  62. 40 PRINT LEFT$ (DOWN$,V);
  63. 50 PRINT "HERE."
  64. 60 GOTO 20
  65. 100 rem string initialization
  66. 110 ACROSS$ = "<home>"
  67. 120 FOR C = 1 TO 40
  68. 130 ACROSS$ = ACROSS$ + "<crsr rt>"
  69. 140 NEXT C
  70. 150 FOR C = 1 TO 25
  71. 160 DOWN$ = DOWN$ + "<crsr dn>"
  72. 170 NEXT C
  73. 180 RETURN
  74.  
  75.  
  76. As you can see, PLOT may result in
  77.  
  78. substantial code compression.
  79.  
  80.  
  81.  
  82.  
  83. How PLOT works:
  84.  
  85. (This may get a bit technical.  If
  86.  you don't understand it, it's safe
  87.  to ignore it.)
  88.  
  89.  
  90.   Locations 781, 782, and 783 are for
  91.  
  92. temporary storage of the processor X,
  93.  
  94. Y, and STATUS registers.
  95.  
  96.  
  97.   Plot first checks the status
  98.  
  99. register's CARRY flag.  If it is
  100.  
  101. reset plot will move the cursor to the
  102.  
  103. horizontal position found in the Y
  104.  
  105. register (782), and the vertical
  106.  
  107. position found in X (781).  [The carry
  108.  
  109. flag is bit 0 of the status register,
  110.  
  111. so POKE 783,0 resets the carry flag
  112.  
  113. and all the other flags.]
  114.  
  115.  
  116.  
  117.   If carry is set (poke 783,1),
  118.  
  119. then PLOT calculates the cursor's
  120.  
  121. current position and places the
  122.  
  123. horizontal coordinate in Y (782) and
  124.  
  125. the vertical in X (781).  You can then
  126.  
  127. peek X and Y and use the values in
  128.  
  129. your BASIC program.
  130.  
  131.  
  132.  
  133.   And a final note:  the carry flag is
  134.  
  135. volatile.  Many BASIC functions set
  136.  
  137. and reset the carry flag.  If you
  138.  
  139. use PLOT, you should poke the carry
  140.  
  141. status EVERY time you PLOT and not
  142.  
  143. just once at the beginning of your
  144.  
  145. program.
  146.  
  147. --------------------------------------
  148.